<template>
  <div class="login">
    <img src="../../../assets/img/noGroup.png" alt="">
    <div>
      <Form ref="identityForm" :model="identityForm" class="login_input" >
        <FormItem prop='name' :rules="validator.chinese" :maxlength="15">
          <Input type="text" v-model="identityForm.name" placeholder="请输入姓名" class="login_input-user"></Input>
        </FormItem>
        <FormItem prop='cerno' :rules="validator.cerno">
          <Input type="text" v-model="identityForm.cerno" placeholder="请输入身份证号码" class="login_input-user"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" long @click="handleSubmit()">开始认证</Button>
        </FormItem>
      </Form>
    </div>
    <div class="login_bottom">
      <MyFooter />
    </div>
  </div>
</template>

<script>
  import MyFooter from '../../../components/MyFooter.vue'
  import request from '../../../utils/request.js'
  import validator from '../../../utils/validatorUtil.js'
    export default {
      data() {
        return {
          validator,
          identityForm: {
            name: '',
            cerno: ''
          }
        }
      },
      mounted() {
        localStorage.setItem('regorg', this.$route.params.regorg)
      },
      methods: {
        handleSubmit() {
          this.$refs['identityForm'].validate((valid) => {
            if (valid) {
              request.get('/interface/out/wechat/goToIdentity.do', {
                name: this.identityForm.name,
                cerno: this.identityForm.cerno,
                regorg: this.$route.params.regorg
              }
              ).then((response) => {
                if (response.data.result === 'error') {
                  this.$ErrorAlert(response.data.message)
                } else {
                  let url = 'https://iauth.wecity.qq.com/new/cgi-bin/auth.php'
                  debugger
                  let params = {}
                  params.appid = response.data.data.appid
                  params.redirect = response.data.data.redirect
                  params.sceneID = response.data.data.sceneID
                  params.signature = response.data.data.signature
                  params.out_trade_no = response.data.data.out_trade_no
                  params.type = response.data.data.type
                  params.uid = response.data.data.uid
                  params.ID = response.data.data.ID
                  params.name = response.data.data.name
                  // 请求跳转路径
                  var temp = document.createElement('form')
                  temp.action = url
                  temp.method = 'post'
                  temp.style.display = 'none'
                  for (var x in params) {
                    var opt = document.createElement('textarea')
                    opt.name = x
                    opt.value = params[x]
                    temp.appendChild(opt)
                  }
                  document.body.appendChild(temp)
                  temp.submit()
                  return temp
                }
              })
            }
          })
        }
      },
      components: {
        MyFooter
      }

    }
</script>

<style scoped>
.login{
  padding: 0 .54rem;
  overflow: hidden;
}
.login img{
  display: block;
  margin: 2rem auto;
}
.login_input{
  margin-top: 3rem;
}
.login .login_input .login_input-user{
  width: 100%;
}
.login_bottom{
  width: 90%;
}
.myfooter{
  /*margin-top: 7rem;*/
}
</style>
